package com.foreknow.elm.controller;

import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.OrderService;
import com.foreknow.elm.service.impl.OrderServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


public class OrdersController {
    public Object createOrders(HttpServletRequest request) {
        String userId = request.getParameter("userId");
        Integer businessId = Integer.valueOf(request.getParameter("businessId"));
        Integer daId = Integer.valueOf(request.getParameter("daId"));
        Double orderTotal = Double.valueOf(request.getParameter("orderTotal"));
        OrderService service = new OrderServiceImpl();
        int orderId = service.createOrders(userId,businessId,daId,orderTotal);
        return orderId;
    }

    public Object getOrdersById(HttpServletRequest request) {
        Integer orderId = Integer.valueOf(request.getParameter("orderId"));
        OrderService service = new OrderServiceImpl();
        Orders orders = service.getOrdersById(orderId);
        return orders;
    }

    public Object listOrdersByUserId(HttpServletRequest request) {
        String userId = request.getParameter("userId");
        OrderService service = new OrderServiceImpl();
        List<Orders> list = service.listOrdersByUserId(userId);
        return list;
    }
}
